package com.apexedu.eas.exception;

import java.util.HashMap;
import java.util.Map;

/**
 * 教务系统异常类
 * Created with IntelliJ IDEA.
 * User: ly
 * Date: 13-11-6
 * Time: 下午3:07
 * To change this template use File | Settings | File Templates.
 */
public class EasException extends RuntimeException {
	/**
	 * 未知错误
	 */
	public static final int UNKNOWN_SERVICE_ERROR = 0;

    /**
     * memcache错误
     */
    public static final int MEMCACHE_ERROR = 1;
    
    /**
     * 分页参数错误
     */
    public static final int PAGER_ERROR = 2;
    /**
     * SQL参数名称错误
     */
    public static final int SQL_ARG_NAME_ERROR = 3;
    
	/**
	 * 默认错误信息
	 */
	private static Map<Integer, String> defaultMessages = new HashMap<Integer, String>();

	static {
		defaultMessages.put(UNKNOWN_SERVICE_ERROR, "未知错误");
		
		defaultMessages.put(PAGER_ERROR, "分页对象不能null");
		defaultMessages.put(SQL_ARG_NAME_ERROR, "存储sql语句的变量名必须为  \"sql\" ,示例：public Object f (String sql) {}");
	}

	public static String getDefaultMessage(int code) {
		return defaultMessages.get(code);
	}

	private static final long serialVersionUID = -6063752879754150583L;

	private int errorcode = UNKNOWN_SERVICE_ERROR;

	public EasException(int code, String message) {
		super(message == null ? getDefaultMessage(code) : message);
		this.errorcode = code;
	}
	public EasException(int code) {
		super(getDefaultMessage(code));
		this.errorcode = code;
	}

	public int getErrorcode() {
		return errorcode;
	}

	public void setErrorcode(int errorcode) {
		this.errorcode = errorcode;
	}
}
